<template>
	<view>
		<baseForm :column.sync="column" @submitFun="submitFun" :submitStatus="submitDisable" :button="button"></baseForm>
		<!-- <progressBox :progressValue="status" :progressInfo="progressInfo"></progressBox> -->
		<progressBox :auditVos="auditVos" dictcode="dict_audit_status"></progressBox>
	</view>
</template>

<script>
import baseForm from '@/wxcomponents/form/form.vue';
import pickerModule from '@/wxcomponents/form/picker.vue';
import { format, dectList,dictCode } from '@/libs/common.js';
import common from '@/libs/login.js';
import progressBox from '@/wxcomponents/commonLayout/progressLevel.vue';
export default {
	data() {
		return {
			user: '',
			itemData: '',
			column: [
				{
					label: '请假人', //输入框title
					name: 'studentName', //传值类型
					type: 'normalInput', //输入框类型
					disabled: true, //是否禁用
					required: true, //是否必须填写
					value: '' //输入框的值
				},
				{
					label: '请假类型',
					name: 'leaveType',
					type: 'picker',
					required: true,
					disabled: true,
					value: '',
					text: '请选择请假类型',
					mode: 'selector', //picker的类型
					range: [] //picker的选项集合
				},
				{
					label: '请输入请假原因',
					name: 'leaveReason',
					type: 'normalInput',
					disabled: true,
					required: true,
					value: ''
				},
				{
					label: '请假起始时间',
					value: '',
					required: true,
					name: 'startTime',
					type: 'picker',
					mode: 'date',
					text: '请选择',
					start:format('YY-mm-dd',new Date())
				},
				{
					label: '请假结束时间',
					value: '',
					required: true,
					name: 'endTime',
					type: 'picker',
					mode: 'time',
					text: '请选择',
				},
				{
					label: '附件',
					type: 'upload',
					url: '/stu/common/uploadFile',
					docFileId: '',
					docFileUrl: '',
					attachmentVoListStr: '',
					disabled: true
				}
			],
			button: {
				hide: true
			},
			progressInfo: [
				{
					name: '审批通过',
					value: 2
				},
				{
					name: '审批中',
					value: 1
				},
				{
					name: '已提交',
					value: 0
				}
			],
			status: 1,
			auditVos: ''
		};
	},
	async onLoad(option) {
		await this.dictList();
		// await this.getCourseNum();
		this.itemData = JSON.parse(option.data);
		await this.setColumn(this.itemData);
		this.getDetail(this.itemData.id);
	},
	methods: {
		async setColumn(data) {
			this.column.forEach(item => {
				//type == input 时候，type== radio的时候，value为items里的选项的value值；type==picker时候 ，value为range的索引值
				if (item.type == 'normalInput') {
					item.value = data[item.name];
				} else if (item.type == 'picker') {
					// this.timeMode()
					if (item.mode == 'selector') {
						// item.text = `第${data[item.name]}节课`;
						let i =data[item.name]
						let arr = item.range.filter(ele=>
							 ele.id == data[item.name]
						)
						item.text = arr[0].name;
					} else {
						item.text = data[item.name];
					}
				} else if (item.type == 'radio') {
					item.value = data[item.name];
				} else {
					return false;
				}
			});
		},
		//获取请假类型,请假时间类型
		async dictList() {
			let resp = await dectList('dict_student_leave_type');
			let leaveDays = await dectList('dict_student_leave_days'); //请假的时间：一天内，或者多天

			this.column[1].range = resp.map(item => {
				return {
					id: item.dictValue,
					name: item.dictName
				};
			});
			// this.column[3].items = leaveDays.map(item => {
			// 	if (item.dictValue == 1) {
			// 		return {
			// 			value: item.dictValue,
			// 			name: '请假时间一日内'
			// 		};
			// 	} else {
			// 		return {
			// 			value: item.dictValue,
			// 			name: '请假时间超过一日'
			// 		};
			// 	}
			// });
		},
		//获取节次
		// async getCourseNum() {
		// 	let resp = await this.$http.get({
		// 		url: '/edu/term/getCurrentTermInfo',
		// 		data: ''
		// 	});
		// 	let len = resp.result.morningTimes + resp.result.afternoonTimes + resp.result.eveningTimes;
		// 	for (let i = 0; i < len; i++) {
		// 		this.column[4].range.push({
		// 			name: `第${i + 1}节课`,
		// 			id: i + 1
		// 		});
		// 		this.column[5].range.push({
		// 			name: `第${i + 1}节课`,
		// 			id: i + 1
		// 		});
		// 	}
		// },
		//获取申请记录详情
		async getDetail(id) {
			let resp = await this.$http.get({
				url: `/stu/studentLeave/detail/${id}`
			});
			this.column[5].attachmentVoListStr = resp.result.attachmentVoListStr;
			this.auditVos = resp.result.auditVos;
		},
		//改变column时间选择模式
		// timeMode() {
		// 	if(this.column[3].value==1){
		// 		this.column[4].label = '从今天';
		// 		this.column[5].label = '到今天';
		// 		this.column[4].name = 'startTimeIndex';
		// 		this.column[5].name = 'endTimeIndex';
		// 		this.column[4].mode = 'selector';
		// 		this.column[5].mode = 'selector';
		// 	}else{
		// 		this.column[4].label = '开始';
		// 		this.column[5].label = '结束';
		// 		this.column[4].name = 'startTime';
		// 		this.column[5].name = 'endTime';
		// 		this.column[4].mode = 'date';
		// 		this.column[5].mode = 'date';
		// 	}
		// }
	},
	components: {
		baseForm,
		pickerModule,
		progressBox
	}
};
</script>

<style></style>
